home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / Gooey 1.2 / Gooey 68K ƒ / C++ Templates / Common.c < prev    next >
Encoding:
Text File  |  1995-02-06  |  11.3 KB  |  373 lines  |  [TEXT/KAHL]

  1. $$Message User Types, u:Types$Prototype.name$.h
  2. $$File u:Types$Prototype.name$.h
  3. /*  Types$Prototype.name$                         types */
  4. /*  $CopyRight$ */
  5.  
  6. /* 
  7.     File name:  Types$Prototype.name$.h   
  8.     Function:  Type definitions for user changes.
  9.     History: $Date$ Original by $Author$
  10.  
  11.    */
  12.  
  13. /* ======================================================= */
  14. /* ======================================================= */
  15.  
  16. class CApplication: public CmmApplication{            /* The Application itself */
  17.     public:
  18.     virtual void InitExtras(void);                    /* override */
  19.     virtual void ExitExtras(void);                    /* override */
  20. $$if Option.EXTRAHOOKS
  21.     virtual void    TopOfLoop(void);                /* HOOK at top of main event loop */
  22.     virtual void    FilterEvent(Boolean *DoIt,EventRecord *myEvent);    /* HOOK, Filter events from the main loop */
  23.     virtual void    Handle_Extra_User_Event(UserEventPRec theUserEvent);    /* Hook, to handle user events */
  24.     virtual void    OpenSplashWindow(void);            /* Open spash or personalization window */
  25.     virtual void    CloseSplashWindow(void);        /* Close spash or personalization window */
  26. $$endif Option.EXTRAHOOKS
  27. };
  28.  
  29.  
  30. class CMenus: public CmmMenus{                        /* The Menu handlers */
  31.     public:
  32.     virtual void AddExtraMenus(void);                /* override */
  33. $$if Option.EXTRAHOOKS
  34.     virtual void    EnableTheMenus(void);            /* Enable or disable before they are dropped */
  35.  
  36. $$Loop Menus
  37.     virtual Boolean    DoMenu$Menu.name$(short theItem);    /* Handle this menu list, $Menu.FullName$ */
  38. $$EndLoop Menus
  39. $$Loop HierMenus
  40.     virtual Boolean    DoMenu$Menu.name$(short theItem);    /* Handle this menu list, $Menu.FullName$ */
  41. $$EndLoop HierMenus
  42. $$endif Option.EXTRAHOOKS
  43. };
  44.  
  45. class CPreferences: public CmmPreferences{            /* The Preferences routines */
  46.     public:    
  47.     virtual void    Init(void);                        /* override */
  48.     virtual void    USetPreferences(Handle thePrefsH); /* override */
  49.     virtual void    UGetPreferences(Handle thePrefsH); /* override */
  50. };
  51.  
  52. class CFiles: public CmmFiles{                    /* The Files routines */
  53.     public:    
  54.     virtual void Close_The_Input_File(void);
  55.     virtual void Open_The_File(void);
  56.     virtual void Close_The_Output_File(void);
  57.     virtual void Save_The_File(void);
  58.     virtual void Select_Volume(void);
  59. };
  60.  
  61. class CPrinting: public CmmPrinting{                /* The Printing routines */
  62.     public:    
  63.     virtual void    Print_The_Data(void);            /* Override */
  64. };
  65.  
  66. $$Loop Alerts
  67. /* Class for the Alert titled  "$Worksheet.FullName$" */
  68. class CA$Worksheet.name$: public CmmA$Worksheet.name${        /* The window */
  69.     public:
  70.     virtual void    Init(void);                /* Override, Initialize the window variables */
  71. $$if Option.EXTRAHOOKS
  72.     virtual void    DoFirstTime(void);        /* HOOK, Handle setup necessary for first time in */
  73.     virtual void    DoItemHit(short itemHit);    /* HOOK, Handle setup necessary for first time in */
  74. $$endif Option.EXTRAHOOKS
  75. };
  76.  
  77. $$EndLoop
  78. $$Loop ModalDialogs
  79. /* Class for the Modal Dialog titled  "$Worksheet.FullName$" */
  80. class CD$Worksheet.name$: public CmmD$Worksheet.name${        /* The window */
  81.     public:
  82.     virtual void    Init(void);                /* Override, Initialize the window variables */
  83. $$if Option.EXTRAHOOKS
  84.     virtual void    Refresh(void);                    /* Update the Dialog */
  85.     virtual void    ExtraSetup(void);
  86.     virtual void    DoItemHit(short *itemHit,Boolean *ExitDialog);    /* Let user handle the item hit */
  87.     virtual void    Exit(void);                /* Exit the dialog */
  88. $$endif Option.EXTRAHOOKS
  89. };
  90.  
  91. $$EndLoop
  92. $$Loop ModelessDialogs
  93. /* Class for the Modeless Dialog titled  "$Worksheet.FullName$" */
  94. class CMD$Worksheet.name$: public CmmMD$Worksheet.name${        /* The window */
  95.     public:
  96.     virtual void    Init(void);                /* Override, Initialize the window variables */
  97. $$if Option.EXTRAHOOKS
  98.     virtual void    UpdateExtras(void);        /* HOOK, allow user update code in */
  99.     virtual void    OpenExtras(void);        /* HOOK, allow user open code in */
  100.     virtual void    Close(WindowPtr theWindow);
  101.     virtual void    HandleEvent(EventRecord *theEvent,WindowPtr theWindow,short itemHit);
  102. $$endif Option.EXTRAHOOKS
  103. };
  104.  
  105. $$EndLoop
  106. $$Loop Windows
  107. /* Class for the window titled  "$Worksheet.FullName$" */
  108. class CW$Worksheet.name$: public CmmW$Worksheet.name${        /* The window */
  109.     public:
  110.     virtual void    Init(void);                /* Override, Initialize the window variables */
  111. $$if Option.EXTRAHOOKS
  112.     virtual void    OpenExtras(Ptr theWS);
  113.     virtual void    CloseExtras(Ptr theWS);
  114.     virtual void    UpdateExtras(Ptr theWS);
  115.     virtual void    ActivateExtras(Boolean Do_An_Activate,Ptr theWS);
  116.     virtual void    HandleExtraButtons(Ptr theWS,ControlHandle theControl,short *UnHiliteValue);
  117. $$if Worksheet.CheckboxesOrRadios
  118.     virtual void    HandleExtraCheckboxes(Ptr theWS,ControlHandle theControl);
  119. $$endif
  120. $$if Worksheet.Scrollbars
  121.     virtual void    HandleScrollBar(short code,ControlHandle theControl,Point myPt);
  122. $$endif
  123.     virtual void    HandleEvent(EventRecord *myEvent);
  124. $$endif Option.EXTRAHOOKS
  125. };
  126.  
  127. $$EndLoop
  128.  
  129.  
  130. /* ======================================================= */
  131. /* ======================================================= */
  132. $$CloseFile
  133. $$Message User Common, u:common$Prototype.name$.h
  134. $$File u:common$Prototype.name$.h
  135. /*  common$Prototype.name$                         Common */
  136. /*  $CopyRight$ */
  137.  
  138. /* 
  139.     File name:  common$Prototype.name$.h   
  140.     Function:  Common variables for program specific code.
  141.     History: $Date$ Original by $Author$
  142.  
  143.    */
  144.  
  145. /* ======================================================= */
  146. /* ======================================================= */
  147.  
  148. #define    PrefsCreator        'xxxx'            /* Creator, this has to be the same as your App */
  149. #define    PrefsType                'Pref'            /* Type, this has to match the type in your BNDL */
  150. #define    PrefsFileName        "\p$Prototype.name$ Prefs"    /* This is the name of your prefs file */
  151.  
  152. #define    PrefsFormatRevision        1            /* Change each time the format changes */
  153.  
  154. /* NOTE : FormatRevision MUST be first in the record, and always a short */
  155. typedef struct PrefsRec{                            /* Preferences Record definition */
  156.     /* ALWAYS KEEP FormatRevision AS THE FIRST ELEMENT IN THIS RECORD */
  157.     short            FormatRevision;        /* FIRST ALWAYS, Change each time the format changes */
  158.     WindowLocRec    theWindowLocRec;    /* For saving window positions */
  159.  
  160.     /* Add other preference variable definitions after this line */
  161.  
  162. }PrefsRec,*PrefsPRec,**PrefsHRec;
  163.  
  164. /* ======================================================= */
  165. /* ======================================================= */
  166. $$CloseFile
  167. $$Message User Common, u:common$Prototype.name$.cp
  168. $$File u:common$Prototype.name$.cp
  169. /*  common$Prototype.name$                         Common */
  170. /*  $CopyRight$ */
  171.  
  172. /* 
  173.     File name:  common$Prototype.name$  
  174.     Function:  Common variables for program specific code. 
  175.     History: $Date$ Original by $Author$
  176.  
  177.    */
  178.  
  179.  
  180. #include "mmCommon$Prototype.name$.h"    /* Common */
  181. #include "common$Prototype.name$.h"        /* Common */
  182.  
  183. /* ======================================================= */
  184. /* ======================================================= */
  185.  
  186. /* ======================================================= */
  187.  
  188. /* Routine: Init */
  189. /* Purpose: Set the default preferences */
  190.  
  191. void CPreferences::Init(void)
  192. {
  193. inherited::Init();
  194. }
  195.  
  196. /* ======================================================= */
  197.  
  198. /* Routine: USetPreferences */
  199. /* Purpose: Set new preferences, to be written out to the file */
  200.  
  201. void CPreferences::USetPreferences(Handle thePrefsH)
  202. {
  203. PrefsHRec thePrefs;
  204.  
  205. inherited::USetPreferences(thePrefsH);
  206.  
  207. thePrefs = (PrefsHRec)thePrefsH;
  208. /* Use the form:   (*thePrefs)->xxxx = xxxx;    */
  209. }
  210.  
  211. /* ======================================================= */
  212.  
  213. /* Routine: UGetPreferences */
  214. /* Purpose: Get the preferences from the Prefs record already read in */
  215.  
  216. void CPreferences::UGetPreferences(Handle thePrefsH)
  217. {
  218. PrefsHRec thePrefs;
  219.  
  220. inherited::UGetPreferences(thePrefsH);
  221.  
  222. thePrefs = (PrefsHRec)thePrefsH;
  223. /* Use the form:   xxxx = (*thePrefs)->xxxx;    */
  224. }
  225.  
  226. /* ======================================================= */
  227. /* ======================================================= */
  228.  
  229. /* Routine: Close_The_Input_File */
  230. /* Purpose: Close the input file */
  231.  
  232. void CFiles::Close_The_Input_File()
  233. {
  234. inherited::Close_The_Input_File();
  235. }
  236.  
  237. /* ======================================================= */
  238.  
  239. /* Routine: Close_The_Output_File */
  240. /* Purpose: Close the output file */
  241.  
  242. void CFiles::Close_The_Output_File()
  243. {
  244. inherited::Close_The_Output_File();
  245. }
  246.  
  247. /* ======================================================= */
  248.  
  249. /* Routine: Open_The_File */
  250. /* Purpose: Open the input file */
  251.  
  252. void CFiles::Open_The_File()
  253. {
  254. short    NumberOfTypes;
  255. short    theVolRefNum;
  256. OSErr    ErrorCode;
  257.  
  258.  
  259. this->Files.typeList[0] = 'TEXT';                            /* Open TEXT files */
  260. this->Files.typeList[1] = 'text';                            /* Open other files */
  261. NumberOfTypes = 1;                                    /* Only use first filetype in the list */
  262. if (Do_The_Open_File(NumberOfTypes,&theVolRefNum,nil,nil))/* Try to open the file */
  263.     {
  264.     ErrorCode = FSOpen(this->Files.inputFileName,this->Files.Reply.vRefNum,&this->Files.inputRefNum);/* Open the file */
  265.     
  266.     /* ADD in your code here to read the file */
  267.     
  268.     this->Close_The_Input_File();                            /* Now close this file */
  269.     }
  270. }
  271.  
  272. /* ======================================================= */
  273.  
  274. /* Routine: Select_Volume */
  275. /* Purpose: Select a volume */
  276.  
  277. void CFiles::Select_Volume()
  278. {
  279. FSSpec    theFile;
  280.  
  281.  
  282. if (Has.NewStdFile)                                    /* Do this if we have new Standard File available */
  283.     {
  284.     if (this->Do_The_Select_Volume(&theFile))
  285.         {
  286.         }
  287.     }
  288. else
  289.     {
  290.     }
  291. }
  292.  
  293. /* ======================================================= */
  294.  
  295. /* Routine: Save_The_File */
  296. /* Purpose: Save the file */
  297.  
  298. void CFiles::Save_The_File()
  299. {
  300. short    theVolRefNum;
  301. short    theRefNum;
  302.  
  303.  
  304. if (this->Do_The_Save_File('xxxx', 'TEXT',(Str255 *)"\pSave as:",(Str255 *)"\pUntitled",/* Try to save the file */
  305.     &theVolRefNum,&theRefNum,nil))
  306.     {
  307.  
  308.     /* ADD in your code here to save the file */
  309.  
  310.     this->Close_The_Output_File();                    /* Now close this file */
  311.     }                                                /* End of IF */
  312. }
  313.  
  314. /* ======================================================= */
  315.  
  316. /* Routine: Print_The_Data */
  317. /* Purpose: Print the data */
  318.  
  319. void CPrinting::Print_The_Data()
  320. {
  321. GrafPtr    ThePrintPort;                                /* Print port */
  322. GrafPtr    SavedPort;                                    /* saved window port */
  323. short    Doing_Page;                                    /* Current print page number */
  324. short    NumberOfCopies;                                /* Number of copies of each page */
  325. short    Count;                                        /* Number of copies of each page */
  326. Boolean    Cancelled;                                    /* User cancelled flag */
  327. short    NumberOfPages;                                /* Change this for the number of pages to do */
  328. Str255    ThePageString;                                /* For showing the page number */
  329.  
  330.  
  331. GetPort(&SavedPort);                                /* Get the current window port */
  332.  
  333. NumberOfPages = 2;                                    /* CHANGE for your pages limit */
  334. this->OpenThePrinter(&Cancelled);                    /* Ask about the next page */
  335.  
  336. if ((Printing.pPrPort != NIL) && (Printing.hPrint != NIL) &&  (!Cancelled))
  337.     {
  338.     ThePrintPort = (GrafPtr)Printing.pPrPort;        /* Get the current window port */
  339.     SetPort(ThePrintPort);                            /* Point to the printer port */
  340.     TextFont(systemFont);
  341.     TextSize(12);
  342.     Doing_Page = 0;
  343.  
  344.     do                                                /* Do all the pages in our document */
  345.         {
  346.         InitCursor();
  347.         Doing_Page = Doing_Page + 1;                /* Bump the page count */
  348.  
  349.         PrOpenPage(Printing.pPrPort, nil);            /* Open a new page */
  350.         SetPort(ThePrintPort);
  351.  
  352.         /* ADD YOUR PRINTING CODE HERE, DRAW INTO THIS PORT */
  353.         MoveTo(10, 20);
  354.         DrawString((StringPtr)"\pPrinting from Marksman™ code, page ");
  355.         NumToString(Doing_Page,ThePageString);
  356.         DrawString(ThePageString);
  357.         /* END OF ADD YOUR PRINTING CODE HERE */
  358.  
  359.         PrClosePage(Printing.pPrPort);                /* Print this page */
  360.         SetPort(SavedPort);
  361.         }
  362.     while (Doing_Page < NumberOfPages);
  363.     }
  364.  
  365. this->CloseThePrinter();                            /* Close the printer */
  366. SetPort(SavedPort);
  367. InitCursor();
  368. }
  369.  
  370. /* ======================================================= */
  371. /* ======================================================= */
  372. $$CloseFile
  373.